/*
========================================================================
 Name        : AacPlayer.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/

#include "AacPlayer.h"

// audio file path
_LIT(KAudioFile, "c:\\data\\sounds\\Friend.aac");

/**
 * First phase of Symbian two-phase construction. Should not 
 * contain any code that could leave.
 */
CAacPlayer::CAacPlayer(): iPlayer ( NULL )
	{
	
	}

/**
 * Second phase of construction
 */
void CAacPlayer::ConstructL()
	{
	// create an instance of CDrmPlayerUtility to play KAudioFile.
	// use this as the callback and set priority normal
	iPlayer = CDrmPlayerUtility::NewFilePlayerL( KAudioFile, *this,
			EMdaPriorityNormal, EMdaPriorityPreferenceNone );
	}

/**
 * First phase of construction
 * Create an instance, not left on clean stack
 */
CAacPlayer* CAacPlayer::NewL()
	{
	CAacPlayer* self = new (ELeave)CAacPlayer;
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

/**
 * Release all resources
 */
CAacPlayer::~CAacPlayer()
	{
	delete iPlayer;
	iPlayer = NULL;
	}
/**
 * Callback when player init complete
 * @param aError error id if occurs
 * @param aDuration duration of audio
 */
void CAacPlayer::MdapcInitComplete(TInt aError, 
		const TTimeIntervalMicroSeconds& /*aDuration*/)
	{
	// if any error occurs leave it
	User::LeaveIfError( aError );
	// request the player to play
	iPlayer->Play();
	}
/**
 * Callback when audio play complete
 * @param aError error id if ocurrs
 */
void CAacPlayer::MdapcPlayComplete( TInt aError )
	{
	User::LeaveIfError( aError );
	}
